package com.caocaog.market.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caocaog.market.entity.MartResearchHis;
import com.caocaog.market.mapper.MartResearchHisMapper;
import com.caocaog.market.service.MartResearchHisService;
import org.jeecg.common.exception.JeecgBootException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 市场调研
 *
 * @author chechen
 * @date 2022-01-13
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MartResearchHisServiceImpl extends ServiceImpl<MartResearchHisMapper, MartResearchHis> implements MartResearchHisService {

    @Override
    public IPage<MartResearchHis> queryMartResearchHisPage(Page<MartResearchHis> page, MartResearchHis martResearchHis) {
        return super.baseMapper.selectPage(page, new LambdaQueryWrapper<MartResearchHis>()
                .eq(MartResearchHis::getTitle, martResearchHis.getTitle()));
    }

    @Override
    public String addMartResearchHis(MartResearchHis martResearchHis) {
        super.baseMapper.insert(martResearchHis);
        if (martResearchHis.getId() == null) {
            throw new JeecgBootException("新增市场调研历史信息失败");
        }
        return martResearchHis.getId();
    }
}
